package com.lottery.im.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <一句话功能简述>
 * 通用工具类
 *
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class Utils {

  /**
   * 验证11位的手机号
   * <一句话功能简述>
   * <功能详细描述>
   *
   * @return boolean [返回类型说明]
   * @throws throws [违例类型] [违例说明]
   * @see [类、类#方法、类#成员]
   */
  public static boolean isPhoneNumber(String phone) {
    String check = "^(13|15|18|14|17)\\d{9}$";
    Pattern regex = Pattern.compile(check);
    Matcher matcher = regex.matcher(phone);
    boolean isMatched = matcher.matches();
    return isMatched;
  }

  public static boolean isIdentity(String identity) {
    String check = "(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)";
    Pattern regex = Pattern.compile(check);
    Matcher matcher = regex.matcher(identity);
    boolean isMatched = matcher.matches();
    return isMatched;
  }

  public static boolean isInteger(String value) {
    try {
      Integer.parseInt(value);
      return true;
    } catch (NumberFormatException e) {
      return false;
    }
  }
}
